#!/bin/sh
#删除grub.cfg中的submenu和 }

GRUBCFG="/boot/grub/grub.cfg"
n=`cat $GRUBCFG |grep menuentry |awk '/bzdtech/ {print NR}' |head -1`
echo $n
n=$(expr $n - 1)
sed -i 's/default="0"/default="'$n'"/' $GRUBCFG

row=`cat $GRUBCFG |awk '/submenu/ {print NR}'`
echo $row
sed -i ''$row'd' $GRUBCFG

while true
do
	row=$(expr $row + 1)
	ch=`sed -n ''$row'p' $GRUBCFG |awk '{print $1}'`
	if [ $ch = "}" ]; then
		row=$(($row+1))
		ch=`sed -n ''$row'p' $GRUBCFG |awk '{print $1}'`
		if [ $ch = "}" ]; then
			sed -i ''$row'd' $GRUBCFG
			break
		fi
	fi
	if [ $row -gt "1000" ]; then
		break
	fi
done

